package com.example.exercise.sys.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;

import com.example.exercise.sys.vo.SysInterfaceVisitVO;
import com.example.exercise.sys.dao.entity.SysInterfaceVisitEntity;
import com.example.exercise.sys.dao.SysInterfaceVisitDAO;

/**
* 
*/
@Service
public class SysInterfaceVisitService {

    @Autowired
    private SysInterfaceVisitDAO sysInterfaceVisitDAO;

    public List<SysInterfaceVisitVO> findByWhere(Page<?> page, SysInterfaceVisitVO sysInterfaceVisitVO){
        List<SysInterfaceVisitVO> list = new ArrayList<>();
        List<SysInterfaceVisitEntity> list0 = sysInterfaceVisitDAO.findByWhere(page, sysInterfaceVisitVO);
        for (SysInterfaceVisitEntity sysInterfaceVisitEntity : list0) {
            list.add(toSysInterfaceVisitVO(sysInterfaceVisitEntity));
        }
        return list;
    }

    public SysInterfaceVisitVO findByKey(SysInterfaceVisitVO sysInterfaceVisitVO){
        SysInterfaceVisitEntity sysInterfaceVisitEntity = sysInterfaceVisitDAO.findByKey(sysInterfaceVisitVO);
        return toSysInterfaceVisitVO(sysInterfaceVisitEntity);
    }

    public int insert(SysInterfaceVisitVO sysInterfaceVisitVO){
        return sysInterfaceVisitDAO.insert(toSysInterfaceVisitEntity(sysInterfaceVisitVO));
    }

    public int updateByKey(SysInterfaceVisitVO sysInterfaceVisitVO){
        return sysInterfaceVisitDAO.updateByKey(toSysInterfaceVisitEntity(sysInterfaceVisitVO));
    }

    public int deleteByKey(SysInterfaceVisitVO sysInterfaceVisitVO){
        return sysInterfaceVisitDAO.deleteByKey(sysInterfaceVisitVO);
    }

    private SysInterfaceVisitVO toSysInterfaceVisitVO(SysInterfaceVisitEntity sysInterfaceVisitEntity) {
        SysInterfaceVisitVO sysInterfaceVisitVO = new SysInterfaceVisitVO();
                sysInterfaceVisitVO.setId(String.valueOf(sysInterfaceVisitEntity.getId()));
        sysInterfaceVisitVO.setUserId(String.valueOf(sysInterfaceVisitEntity.getUserId()));
        sysInterfaceVisitVO.setInterfaceId(String.valueOf(sysInterfaceVisitEntity.getInterfaceId()));

        return sysInterfaceVisitVO;
    }

    private SysInterfaceVisitEntity toSysInterfaceVisitEntity(SysInterfaceVisitVO sysInterfaceVisitVO) {
        SysInterfaceVisitEntity sysInterfaceVisitEntity = new SysInterfaceVisitEntity();
                String id = sysInterfaceVisitVO.getId();
        if(id != null) {
            sysInterfaceVisitEntity.setId(Integer.parseInt(sysInterfaceVisitVO.getId()));
        }
        String userId = sysInterfaceVisitVO.getUserId();
        if(userId != null) {
            sysInterfaceVisitEntity.setUserId(Integer.parseInt(sysInterfaceVisitVO.getUserId()));
        }
        String interfaceId = sysInterfaceVisitVO.getInterfaceId();
        if(interfaceId != null) {
            sysInterfaceVisitEntity.setInterfaceId(Integer.parseInt(sysInterfaceVisitVO.getInterfaceId()));
        }

        return sysInterfaceVisitEntity;
    }

}